package maze;
/**
 * This class is used for the maze representation in sectors
 * @author s0212373
 *
 */
public class Coordinate {
	public int x;
	public int y;
	public Coordinate(int x, int y) {
		this.x = x;
		this.y = y;
	}
	public int getX(){
		return x;
		
	}
	public int getY(){
		return y;
	}
	@Override
	public boolean equals(Object other){
		if(other instanceof Coordinate){
			Coordinate coord = (Coordinate) other;
			return (coord.getX() == this.getX()) && (coord.getY() == this.getY());
		}
		return false;
	}
	
	@Override
	public int hashCode(){
		int result = 0;
		int c = getX();
		result = 37 * result + c;
		c = getY();
		result += c;
		return result;
	}
	
	@Override
	public String toString(){
		return "" + getX() + "," + getY();
	}
	
	public static Coordinate getCoordinateInDirection(Coordinate coordinate, Direction direction){
		switch(direction){
		case NORTH:
			return new Coordinate(coordinate.getX(),coordinate.getY()+1);
		case EAST: 
			return new Coordinate(coordinate.getX()+1,coordinate.getY());
		case SOUTH: 
			return new Coordinate(coordinate.getX(),coordinate.getY()-1);
		case WEST: 
			return new Coordinate(coordinate.getX()-1,coordinate.getY());
		}
		return null;	
	}
	public Direction getDirectionOfCoordinate(Coordinate coordinate){
		if(coordinate.getY()==this.getY()){
			if(coordinate.getX()==this.getX()+1)
				return Direction.EAST;
			else if(coordinate.getX()==this.getX()-1)
				return Direction.WEST;
		}
		if(coordinate.getX()==this.getX()){
			if(coordinate.getY()==this.getY()+1)
				return Direction.NORTH;
			else if(coordinate.getY()==this.getY()-1)
				return Direction.SOUTH;
		}
		return null;
	}
	
	public static Location toLocation(Coordinate co){
		return new Location((co.getX()*40)+20,(co.getY()*40)+20);
	}
}
